package com.jvtd.demo.im;

import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.widget.TextView;

import com.jvtd.base.JvtdActivity;
import com.jvtd.demo.R;
import com.jvtd.demo.im.bean.MyInfoNotificationMsgItemProvider;
import com.jvtd.demo.im.bean.MyInformationNotificationMessage;
import com.jvtd.rong_im.JvtdRongIM;

import java.util.List;

import io.rong.imkit.RongIM;
import io.rong.imlib.RongIMClient;
import io.rong.imlib.model.Conversation;
import io.rong.imlib.model.Message;

/*
 * 会话列表Activity
 * Create by Jack Zhang
 */
public class ConversationListActivity extends JvtdActivity
{
  public static final String INFO_NOTIFICATION_MSG = "app:info_notification_msg";

  @Override
  protected void bindView()
  {
    Toolbar toolbar = findViewById(R.id.tool_bar);
    setToolbar(toolbar, true);

    TextView tvTitle = findViewById(R.id.tv_title);
    tvTitle.setText("会话列表");
  }

  @Override
  protected void getLayout()
  {
    setContentView(R.layout.activity_conversation_list);
  }

  @Override
  protected void initViewAndData()
  {
    RongIMClient.getInstance().getConversationList(new RongIMClient.ResultCallback<List<Conversation>>()
    {
      @Override
      public void onSuccess(List<Conversation> conversations)
      {
        for (Conversation conversation : conversations)
        {
          Log.i("abcabcabc", conversation.getTargetId());
        }
      }

      @Override
      public void onError(RongIMClient.ErrorCode errorCode)
      {

      }
    });

    JvtdRongIM.getInstance(mContext).registerMessageType(MyInformationNotificationMessage.class)
            .registerMessageTemplate(new MyInfoNotificationMsgItemProvider());

    Message message = Message.obtain("user003", Conversation.ConversationType.PRIVATE, null);

    MyInformationNotificationMessage informationMessage = MyInformationNotificationMessage.obtain("啦啦啦啦啦啦");
    JvtdRongIM.getInstance(mContext).insertOutgoingMessage(Conversation.ConversationType.PRIVATE, message.getTargetId(), Message.SentStatus.SENT, informationMessage, null);
  }
}
